import Vue from 'vue'
import Vuex from 'vuex'

//挂载Vuex
Vue.use(Vuex)

//创建VueX对象
const store = new Vuex.Store({
    state:{
      userInfo: {

        },
        // 答案
        answer: {
            // 选择题
            choice:[],
            // 填空题
            cloze:[],
            // 判断题
            judge:[],
            // 多选题
            multipleChoice:[],
        },
        // 考试信息
        examInfo: {

            id: "",
            // 考试名称
            name: "",
            // 考试时间
            time: 0,
            // 是否已经开始
            isBegin: true,
            // 是否已经结束
            isEnd: false,
            // 是否已经提交,
            isSubmit: true,
        },
        // 试卷信息
        problems: []
    },
    mutations:{
        saveUserInfo(state, userInfo) {
          state.userInfo = userInfo
        },
        saveExamInfo(state, examInfo) {
            state.examInfo = examInfo;
        },
        saveAnswerCloze(state, res) {
            state.answer.cloze[res.index] = res.data;
        },
        saveAnswerChoice(state, res) {
            state.answer.choice[res.index] = res.data;
        },
        saveAnswerJudge(state, res) {
            state.answer.judge[res.index] = res.data;
        },
        saveAnswerMultipleChoice(state, res) {
            state.answer.multipleChoice[res.index] = res.data;
        },
        removeAllAnswer(state) {
          state.answer = {
            // 选择题
            choice:[],
            // 填空题
            cloze:[],
            // 判断题
            judge:[],
            // 多选题
            multipleChoice:[],
          };
        },
        editExamInfo(state, res) {
          state.examInfo.name = res.courseName;
          state.examInfo.id = res.id;
        },
        editExamTime(state, res) {
          state.examInfo.time = res;
        },
        editExamSubmit(state, res) {
          state.examInfo.isSubmit = res;
        },
        saveProblems(state, res) {
          state.problems = res;
        },
    },
    getters:{
        examInfo(state) {
            return state.examInfo;
        },
        answer(state) {
            return state.answer;
        },
        problemsInfo(state) {
          return state.problems;
        },
        userInfo(state) {
          return state.userInfo;
        },
    }
})

export default store
